package jm.demo.jaxb.permission;

import java.util.ArrayList;
import java.util.List;

import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;

@XmlRootElement
@XmlType(propOrder= {"name", "displayName", "securityObjects"})
public class Role {
	
	private String name;
	
	private String displayName;
	
	private List<SecurityObject> securityObjects;
	
	

	public String getName() {
		return name;
	}



	public void setName(String name) {
		this.name = name;
	}



	public String getDisplayName() {
		return displayName;
	}



	public void setDisplayName(String displayName) {
		this.displayName = displayName;
	}



	public List<SecurityObject> getSecurityObjects() {
		return securityObjects;
	}



	public void setSecurityObjects(List<SecurityObject> securityObjects) {
		this.securityObjects = securityObjects;
	}



	public static Role randomOne() {
        Role result = new Role();
        result.setName("roleName-"  + SecurityContextManager.random.nextInt());
        result.setDisplayName("roleDisplayName-"  + SecurityContextManager.random.nextInt());
        List<SecurityObject> security_objects = new ArrayList<SecurityObject>();
        security_objects.add(SecurityObject.randomOne());
        security_objects.add(SecurityObject.randomOne());
        result.setSecurityObjects(security_objects);
        
        return result;
	}



	@Override
	public String toString() {
		return "Role [name=" + name + ", displayName=" + displayName
				+ ", securityObjects=" + securityObjects + "]";
	}



	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((displayName == null) ? 0 : displayName.hashCode());
		result = prime * result + ((name == null) ? 0 : name.hashCode());
		result = prime * result
				+ ((securityObjects == null) ? 0 : securityObjects.hashCode());
		return result;
	}



	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Role other = (Role) obj;
		if (displayName == null) {
			if (other.displayName != null)
				return false;
		} else if (!displayName.equals(other.displayName))
			return false;
		if (name == null) {
			if (other.name != null)
				return false;
		} else if (!name.equals(other.name))
			return false;
		if (securityObjects == null) {
			if (other.securityObjects != null)
				return false;
		} else if (!securityObjects.equals(other.securityObjects))
			return false;
		return true;
	}

	
	
	
}



